package com.topscomm.meet.job;

import com.topscomm.meet.MeetSystemConst;
import com.topscomm.meet.MeetSystemConst.MeetStateEnum;
import com.topscomm.meet.pojo.MeetTaskMasterEntity;
import com.topscomm.meet.service.IMeetTaskDetailService;
import com.topscomm.meet.service.IMeetTaskMasterService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: shenyouyi
 * @date: 2020-08-28
 * @description: 创建会议任务详情Job
 * @modify:
 */
@JobHandler("meetTaskDetailCreateJob")
@Component
public class MeetTaskDetailCreateJob extends IJobHandler {

    @Autowired
    private IMeetTaskMasterService meetTaskMasterService;
    @Autowired
    private IMeetTaskDetailService meetTaskDetailService;

    @Override
    public ReturnT<String> execute(String s) throws Exception {
        // 查询纪要已发布的
        Map<String, Object> paraMap = new HashMap<>();
        paraMap.put("qry_state", MeetStateEnum.Publish);
        List<Map<String, Object>> meetTaskList = meetTaskMasterService.queryMap(paraMap, "queryTaskMasterList");
        for (Map<String, Object> map : meetTaskList) {
            MeetTaskMasterEntity meetTaskMasterEntity = new MeetTaskMasterEntity();
            meetTaskMasterEntity = (MeetTaskMasterEntity) meetTaskMasterEntity.convertFromMap(map);
            if (MeetSystemConst.MeetTaskMasterStateEnum.RELEASE == meetTaskMasterEntity.getState()) {
                meetTaskDetailService.createTaskDetailFromMaster(meetTaskMasterEntity);
            }
        }
        return ReturnT.SUCCESS;
    }

}
